package common;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

/**
 * @author Flavio Ferrara
 * 
 */
public class FileLogger {

	private Logger myLogger;
	private FileHandler fh;
	public FileLogger() throws RuntimeException{
		this.myLogger = Logger.getLogger("");
		try{
			this.fh = new FileHandler(System.getProperty("user.dir")+"/isola.log", true);
		} catch (IOException e){
			throw new RuntimeException(System.getProperty("user.dir")+"/isola.log : IO Error");
		} catch (SecurityException e){
			throw new RuntimeException(System.getProperty("user.dir")+"/isola.log : Operation not permitted");
		}
		
		this.myLogger.addHandler(this.fh);
		this.myLogger.setLevel(Level.INFO);
		this.fh.setFormatter(new SimpleFormatter());
	}
	
	public void logError(String message){
		String myLog = "Error occurred, info: " + message;
		this.myLogger.log(Level.SEVERE, myLog);
	}
	
	public void logInfo(String message){
		String myLog = "Information: " + message;
		this.myLogger.log(Level.INFO, myLog);
	}

}
